const state = {
  dictDataList: [],    // 字典数据集合
  dictDataMap: new Map()  // 字典数据map，key为dictType，value为list dictData
}

const getters = {
  dictDataList: state => state.dictDataList,
  dictDataMap: state => state.dictDataMap
}

const mutations = {
  setDictDataList: (state, list) => {
    state.dictDataList = list

    let map = new Map()
    list.forEach(o => {
      let key = o.dictTypeCode
      let dictList = map.get(key)
      if (dictList === undefined || dictList === null) {
        dictList = []
      }
      dictList.push(o)
      map.set(key, dictList)
    })
    state.dictDataMap = map
  }
}

const actions = {
  setDictDataList: (context, list) => context.commit('setDictDataList', list)
}

export default {
  state,
  getters,
  mutations,
  actions
}
